/**
 * 通用API类型定义
 */

// 统一响应格式
export interface ApiResponse<T = any> {
  code: number
  data: T
  msg: string
}

// 分页请求参数
export interface PageParams {
  pageNo?: number
  pageSize?: number
}

// 分页响应数据
export interface PageResult<T> {
  list: T[]
  total: number
  pageNo: number
  pageSize: number
}

// 通用ID参数
export interface IdParam {
  id: number
}

// 通用状态
export interface StatusParam {
  status: string
}

// 语言类型
export type LanguageType = 'chinese' | 'english' | 'bilingual'

// 阅读模式
export type ReadingMode = 'image' | 'text'

// 计划状态
export type PlanStatus = 'active' | 'paused' | 'completed' | 'cancelled'

// 配音状态
export type RecordingStatus = 'draft' | 'published' | 'deleted'

// 推荐专区类型
export type RecommendationType = 'featured' | 'new' | 'popular' | 'category'

// 音频来源类型
export type AudioSourceType = 'official' | 'user'

// 关注状态
export type FollowStatus = 'following' | 'not_following' | 'mutual'

// 收藏类型
export type FavoriteType = 'book_set' | 'book' | 'recording'

// 通用错误响应
export interface ErrorResponse {
  code: number
  msg: string
  data?: any
}

// 文件上传响应
export interface UploadResponse {
  url: string
  filename: string
  size: number
}

// 搜索参数
export interface SearchParams extends PageParams {
  keyword?: string
  categoryId?: number
  language?: LanguageType
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
}

// 日期范围参数
export interface DateRangeParams {
  startDate?: string
  endDate?: string
}

// 统计数据基础结构
export interface BaseStats {
  total: number
  today: number
  thisWeek: number
  thisMonth: number
}

// 图表数据点
export interface ChartDataPoint {
  date: string
  value: number
  label?: string
}

// 标签信息
export interface TagInfo {
  id: number
  name: string
  color?: string
  count?: number
}

// 用户基础信息
export interface BaseUserInfo {
  id: number
  nickname: string
  avatar?: string
  level?: number
}

// 时间戳信息
export interface TimestampInfo {
  createTime: string
  updateTime?: string
}

// 排序参数
export interface SortParams {
  sortField?: string
  sortOrder?: 'asc' | 'desc'
}

// 批量操作参数
export interface BatchParams {
  ids: number[]
}

// 状态切换参数
export interface ToggleStatusParams {
  id: number
  status: boolean | string
}

// 评分信息
export interface RatingInfo {
  score: number
  maxScore: number
  count?: number
}

// 进度信息
export interface ProgressInfo {
  current: number
  total: number
  percentage: number
}

// 媒体文件信息
export interface MediaInfo {
  url: string
  duration?: number
  size?: number
  format?: string
}

// 地理位置信息
export interface LocationInfo {
  latitude?: number
  longitude?: number
  address?: string
  city?: string
}

// 设备信息
export interface DeviceInfo {
  platform: string
  version: string
  model?: string
}

// 通知信息
export interface NotificationInfo {
  id: number
  title: string
  content: string
  type: string
  isRead: boolean
  createTime: string
}

// 配置项
export interface ConfigItem {
  key: string
  value: any
  type: 'string' | 'number' | 'boolean' | 'object'
  description?: string
}

// 操作日志
export interface OperationLog {
  id: number
  userId: number
  action: string
  target: string
  targetId: number
  details?: string
  createTime: string
}

// 缓存配置
export interface CacheConfig {
  key: string
  ttl: number // 过期时间（秒）
  autoRefresh?: boolean
}

// API请求配置
export interface RequestConfig {
  timeout?: number
  retries?: number
  cache?: boolean
  loading?: boolean
  errorToast?: boolean
}

// 表单验证规则
export interface ValidationRule {
  required?: boolean
  min?: number
  max?: number
  pattern?: RegExp
  message: string
}

// 表单字段配置
export interface FormFieldConfig {
  key: string
  label: string
  type: 'text' | 'number' | 'select' | 'textarea' | 'switch' | 'date'
  rules?: ValidationRule[]
  options?: Array<{ label: string, value: any }>
  placeholder?: string
  disabled?: boolean
}
